//
// Created by aaa on 2025/7/10.
//


#include<bits/stdc++.h>

using namespace std;
const int N = 5050;

int n;
int a[N],b[N];
int len;

int find(int x){
    int l = 1,r = len,mid = 0;
    while(l <= r){
        mid = (l + r) / 2;
        if(x > b[mid]) l = mid + 1;
        else r = mid - 1;
    }
    return l;
}

//最长上升子序列（二分查找）
//6
//1 2 4 1 3 4
int main(){
    cin >> n;
    for(int i = 1;i <= n;i++) cin >> a[i];

    len = 1,b[1] = a[1];

    for(int i = 2,j = 0;i <= n;i++){
        if(a[i] > b[len]){
            b[++len] = a[i];
        }else{
            j = find(a[i]);
            b[j] = a[i];
        }
    }

    cout << len;

    return 0;
}